package com.plz.afmt.utils;


import org.apache.commons.lang3.StringUtils;
import org.reflections.Reflections;

import java.util.Properties;
import java.util.Set;

/**
 * @author swing
 * @date 2019-03-02
 * http工具类
 */
public class ConmonUtils {

    public static final boolean isLinux() {
        Properties prop = System.getProperties();
        String os = prop.getProperty("os.name");
        if (os != null && os.toLowerCase().indexOf("linux") > -1) {
            return true;
        } else {
            return false;
        }
    }

    public static final boolean isBlank(String str) {
        return StringUtils.isBlank(str);
    }

    public static final boolean isNotBlank(String str) {
        return StringUtils.isNotBlank(str);
    }

    public static final Set<Class> getSubInterface(String packName, Class intefaceName) {
        Reflections reflections = new Reflections(packName);
        Set<Class> classes = reflections.getSubTypesOf(intefaceName);
        return classes;
    }

    /**
     * 随机生成短信验证码
     *
     * @param num
     * @return
     */
    public static final String createSmsCode(int num) {
        String result = "";
        for (int i = 0; i < num; i++) {
            int number = (int) Math.ceil(Math.random() * 10);
            result += String.valueOf(number);
        }
        if (result.length() > num) {
            result = result.substring(0, num);
        }
        return result;
    }
}
